package Service;


import Dao.SearchUserByPageDao;
import Table.PageBean;
import Table.User;

import java.util.ArrayList;

public class SearchUserByPageService {
    public static PageBean<User> FindUser(String currentPage, String rows, String username) {
        int rows1 = Integer.parseInt(rows);
        int currentPage1 = Integer.parseInt(currentPage);
        PageBean<User> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage1);
        pageBean.setRows(rows1);
        int totalCount = SearchUserByPageDao.FindTotalCount(username);
        pageBean.setTotalCount(totalCount);

        int start = (currentPage1 - 1) * rows1;
        ArrayList<User> list = SearchUserByPageDao.FindByPage(start, rows1, username);
        pageBean.setList(list);

        int totalPage = (totalCount % rows1) == 0 ? totalCount / rows1 : (totalCount / rows1) + 1;
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }
}
